package haoyc.handler;

import haoyc.entity.User;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

import java.net.InetAddress;
import java.util.Scanner;

/**
 * @author Memory
 * @version 1.0
 * @date 2021/11/23
 */
@Slf4j
public class LoginHandler extends ChannelInboundHandlerAdapter {

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        Scanner input = new Scanner(System.in);
        System.out.println("请输入本机名称：");
        String name = input.next();
        ctx.writeAndFlush(new User(name, InetAddress.getLocalHost().getHostAddress()));
    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        super.channelRead(ctx, msg);
    }
}
